/**
*  \file kwptprx.h
*
*  \brief
*
*  \author Michael J. Hohmann  michael.hohmann@linde-mh.de
*
*
*
*
*
*/
#ifndef KWPTPRX_H_INCLUDED
#define KWPTPRX_H_INCLUDED

/*================================================[ public includes  ]================================================*/
#include "../cfg/prj.h"
#include "../kwp/kwp_msg.h"
#include "../canmsg/canmsg.h"

/*================================================[ public defines   ]================================================*/

/*================================================[ public datatypes ]================================================*/
struct kwptprx_obj;

typedef void* (*kwptprx_state_func_t) (struct kwptprx_obj *me, U8 const *data);

typedef void ( *kwptprx_transmit_func_t )( U8 *data);

/** Object definition.
* 
* The struct kwptprx_obj defines the attribute of an object.
*/
struct kwptprx_obj
{	
   struct kwp_msg* buffer;
   U8 block_size;
   U8 separation_time;
   kwptprx_transmit_func_t transmit;

   BO  msg_available;
   U32 expected_sequence_number;
   U32 block_size_counter;
   U16 bytes_received;
   BO  expect_consecutive_frame;
   U32 time_last_message;


   U8 *p_write_data;
   U16 bytes_missing;
};

/*================================================[ public variables ]================================================*/

/*================================================[ inline functions ]================================================*/

/*================================================[ public functions ]================================================*/

/**
*  Constructor.
*
*  Construct an object. 
*
*  \param me Object pointer. NIL will throw an assert.
*  \param block_size Block size will be used in Flow-Control Frame for rx segmented messages.
*  \parma seperation_time Separation time will be used in Flow-Control-Frame for rx segmented messages.
*  \parma timeout    Timeout between messages in segmented transfer.
*  \param pending_time  If the generation of an response (reading from eeprom) take longer than this time pending messages will be send.
*  \param time_base  time base  where the kwpclient_cyclic_service() function will be called.
*
*  \return RC_SUCCESS if successful.
*/
RC kwptprx_construct( struct kwptprx_obj *me, struct kwp_msg* buffer,kwptprx_transmit_func_t transmit_func, U8 block_size, U8 separation_time);
BO kwptprx_process_msg(struct kwptprx_obj *me, U8 *data);
void kwptprx_cyclic_service(struct kwptprx_obj *me);

struct kwp_msg* kwptprx_take_msg(struct kwptprx_obj *me);
void kwptprx_release_msg(struct kwptprx_obj *me);

/*====================================================================================================================*/

#endif

/***********************************************************************************************************************
*                             Copyright 2020 Linde Material Handling. All rights reserved.                             *
***********************************************************************************************************************/
